//
//  LLPublishCell.m
//  LoveLove
//
//  Created by leiyifan on 2019/6/23.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "LLPublishCell.h"

@interface LLPublishCell()

@property (nonatomic,strong) UIView *backView;

@property (nonatomic,strong) UILabel *titleLab;

@property (nonatomic,strong) UILabel *contentLab;

@property (nonatomic,strong) UILabel *timeLab;
@end

@implementation LLPublishCell

-(UIView *)backView{
    if (!_backView) {
        _backView = [UIView new];
        _backView.layer.cornerRadius = 6;
        _backView.layer.masksToBounds = YES;
        _backView.layer.borderColor = [UIColor blackColor].CGColor;
        _backView.layer.borderWidth = 1;
    }
    return _backView;
}

-(UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [UILabel new];
        _titleLab.font = [UIFont systemFontOfSize:14];
        _titleLab.textColor = [UIColor blackColor];
        
    }
    return _titleLab;
}
-(UILabel *)contentLab{
    if (!_contentLab) {
        _contentLab = [UILabel new];
        _contentLab.font = [UIFont systemFontOfSize:14];
        _contentLab.textColor = [UIColor blackColor];
        
    }
    return _contentLab;
}

-(UILabel *)timeLab{
    if (!_timeLab) {
        _timeLab = [UILabel new];
        _timeLab.font = [UIFont systemFontOfSize:14];
        _timeLab.textColor = [UIColor blackColor];
        
    }
    return _timeLab;
}

+ (instancetype)publishCellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseId = @"LLPublishCell";
    LLPublishCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
    if (!cell) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseId andIndexPath:indexPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
// 重写构造方法，初始化（创建自定义cell内部的子控件）
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier andIndexPath:(NSIndexPath *)indexPath
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.backView];
        [self.contentView addSubview:self.titleLab];
        [self.contentView addSubview:self.contentLab];
        [self.contentView addSubview:self.timeLab];
    }
    return self;
}
-(void)configPublishCell:(LLMyPublishModel *)model{
    self.titleLab.text = model.newsTitle;
    self.contentLab.text = [NSString stringWithFormat:@"浏览数:%@   点赞数:%@",model.like_num,model.like_num];
     self.timeLab.text = model.time;
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(8);
        make.top.equalTo(self.mas_top).with.offset(8);
        make.right.equalTo(self.mas_right).with.offset(-8);
        make.bottom.equalTo(self.mas_bottom).with.offset(-8);
    }];
    
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backView.mas_left).with.offset(8);
        make.top.equalTo(self.backView.mas_top).with.offset(8);
    }];
    
    [self.contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLab.mas_left);
        make.top.equalTo(self.titleLab.mas_bottom).with.offset(20);
    }];
    
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentLab.mas_left);
        make.top.equalTo(self.contentLab.mas_bottom).with.offset(20);
    }];
}

@end
